/*
* @Author: Someu
* @Date:   2017-11-30 20:24:47
* @Last Modified by:   Someu
* @Last Modified time: 2017-11-30 23:47:09
*/
require('./index.css');

var _mm = require('util/mm.js');

//通用页面头部
var header = {
    init : function(){
        //绑定事件
        this.bindEvent();
    },
    onLoad : function(){
        var keyword = _mm.getUrlParam('keyword');
        //如果keyword存在，则回填搜索框
        if(keyword){
            $('#search-input').val(keyword);
        }
    },
    bindEvent : function(){
        var _this = this;

        //点击搜索按钮后，搜索提交
        $('#search-btn').click(function(){
            _this.searchSubmit();
        });
        //输入回车后,做搜索提交
        $('#search-input').keyup(function(e){
            if(e.keyCode === 13){
                _this.searchSubmit();
            }
        });
    },
    //搜索提交
    searchSubmit : function(){
        var keyword = $.trim($('#search-input').val());
        //如果提交的时候有keyword,正常跳转到list页
        if(keyword){
            window.location.href = './list.html?keyword='+keyword;
        }else{
            _mm.goHome();
        }
    }

};

header.init();